<?php

namespace app\index\controller;

use think\cache\driver\Redis;
use think\Controller;

class Login extends Controller
{
    public function index()
    {

        $redis=new Redis(config('redis'));
        if(!$redis->get('member_1')){
            $data=array();
            $data['username']="admin";
            $data['password']=md5("a123456");
            $redis->set("member_1",json_encode($data));
        }
        $tips=input('tips')?input('tips'):"";
        $this->assign('tips',$tips);
        return $this->fetch();
    }
    public function login()
    {
        $user=input('username');
        $password=input('password');
        $redis=new Redis(config('redis'));
        $member=$redis->get('member_1');
        $data=json_decode($member,true);
        if($data['username']==$user && $data['password']==md5($password)){
            session('user',$user);
            $this->redirect('index/index');
        }else{
            $this->redirect('login/index',['tips'=>"1"]);
        }
    }
    public function logout()
    {
        session('user',null);
        $this->redirect('login/index');
    }
}